package com.teamawesome.hackathon;


import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import android.widget.AdapterView.OnItemClickListener;

public class ResultsUi extends Activity {

        ListView list;
        LazyAdapter adapter;
        

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.resultsuilist);
            
            Intent i = getIntent();
            
            String [] imgArray = i.getStringArrayExtra("image");
            String [] titleArray = i.getStringArrayExtra("title");
            final String [] urlArray = i.getStringArrayExtra("url");
            String [] priceArray = i.getStringArrayExtra("price");
            
            list=(ListView)findViewById(R.id.list);
            adapter=new LazyAdapter(this, imgArray, titleArray, priceArray);           
            
    		list.setAdapter(adapter);
    		list.setTextFilterEnabled(true);
    		list.setOnItemClickListener(new OnItemClickListener(){

    			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
    					long arg3) {
    				String id = urlArray[arg2];
    				Intent intent = new Intent(Intent.ACTION_VIEW, Uri
    						.parse(id));
    				startActivity(intent);
    				
    			}
    			
    		});
        }
        
        
        @Override
        public void onDestroy()
        {
            adapter.imageLoader.stopThread();
            list.setAdapter(null);
            super.onDestroy();
        }
        
    }